<?php

    // Created By : Julian Ponce
    // B.S. Computer Science - De La Salle Canlubang
    // October 19, 2011
    // IN parameters : 
    // OUT parameters : 

// Start - Checker for those users who will just go to the page by typing directly in the url.
if ($_POST) { 
    // INCLUDES CONFIGURATION VARIABLES FOR DATABASE ACCESS
    $hostName = "localhost";
    $rootName = "dbasegr";
    $dBasePassword = "dbgr2012";
    $dBaseName = 'greenroute';

    
    // CONNECT TO DATABASE
    $connect = mysql_connect($hostName,$rootName,$dBasePassword) or die ('Unable to connect!');
    mysql_select_db($dBaseName) or die ('Unable to select database!');
    
    // GET VARIABLES VIA POST METHOD
    $stepId = $_POST['stepId']; // < This is the current step number of the document.
    
    //GET CURRENT STEP ID BASED ON MAIN DOCUMENT.
    $query = 
        "
            SELECT *
            FROM Step_SubRoute, SubRoute
            WHERE Step_SubRoute.stepId = '$stepId' AND Step_SubRoute.subRouteId = SubRoute.subRouteId
        ";
    $result = mysql_query($query) or die ('Error in query: $query. ' . mysql_error());
    
    //THIS IDENTIFIES IF THERE EXIST SUB ROUTES.
    if (mysql_num_rows($result) > 1) {            
            while ($row = mysql_fetch_array($result)) {
                $subRouteData = array();
                $subRouteData['subRouteId'] = $row['subRouteId'];
                $subRouteData['subRouteName'] = $row['subRouteName'];                
                
                $subRouteList[] = $subRouteData;
            }
    echo json_encode($subRouteList);
    }   
    
    else {
        echo json_encode(0);
    }
    
    mysql_free_result($result);
    mysql_close($connect);
}   // End - Checker for those users who will just go to the page by typing directly in the url.
else {
    echo "Unauthorized access to checkSubRoute.php page. This incident will be reported immediately.";
}
?>

